var o = require("../../../3D336854875DE5CF5B550053BF4D6824.js");

require("../../../FFE95507875DE5CF998F3D00DB5D6824.js"), require("../../../26C7E8E6875DE5CF40A180E17E6D6824.js"), 
getApp().globalData;

Page({
    data: {
        filePath: "",
        navHeight: 0,
        resurl: ""
    },
    onLoad: function(o) {
        var e = this;
        if (null != o.resurl) console.log("resurl有值"), console.log(o.resurl), this.setData({
            resurl: o.resurl
        }); else if (null != o.filePath) {
            console.log("filepath有值");
            var n = o.filePath;
            this.recognize(n, "anime");
        } else console.log("resur和filepath都没有值"), this.setData({
            resurl: ""
        });
        wx.getSystemInfo({
            success: function(o) {
                e.navHeight = o.statusBarHeight + 44, e.setData({
                    windowHeight: o.windowHeight,
                    navHeight: e.navHeight
                });
            }
        });
    },
    onReady: function() {
        console.log("anime.detail.ready");
    },
    onShow: function() {
        console.log("anime.detail.show");
    },
    loadRewardAd: function() {
        var o = this;
        wx.createRewardedVideoAd && (rewardedVideoAd = wx.createRewardedVideoAd({
            adUnitId: "adunit-8ed8fc094c31139a"
        }), rewardedVideoAd.onLoad(function() {
            console.log("激励视频 广告加载成功");
        }), rewardedVideoAd.onError(function(o) {
            console.log("激励广告加载失败", o);
        }), rewardedVideoAd.onClose(function(e) {
            console.log("激励广告关闭", e), e && e.isEnded && o.downloadFromUrl();
        }));
    },
    loadInterstitialAd: function() {
        wx.createInterstitialAd && (interstitialAd = wx.createInterstitialAd({
            adUnitId: "adunit-34c1ba75d34ffbde"
        }), interstitialAd.onLoad(function() {
            console.log("ad onLoad event emit");
        }), interstitialAd.onError(function(o) {
            console.log("ad onError event emit", o);
        }), interstitialAd.onClose(function(o) {
            console.log("ad onClose event emit", o);
        }));
    },
    showInterstitialAd: function() {
        interstitialAd && interstitialAd.show().catch(function(o) {
            console.log("插屏广告显示失败"), console.error(o);
        });
    },
    toBack: function() {
        1 == getCurrentPages().length ? (console.log("length为1"), wx.switchTab({
            url: "/pages/index/index"
        })) : (console.log("length不为1"), wx.navigateBack({}));
    },
    recognize: function(e, n) {
        console.log("anime.detail.recognize"), console.log(e), console.log(n);
        var t = this;
        o.recognizeCommon(e, n, "绘制中...").then(function(o) {
            var e = o.res;
            if (e) {
                if (200 != e.code) return void wx.showToast({
                    title: "无法识别"
                });
                t.setData({
                    resurl: e.result.url
                });
            } else console.log("识别结果有问题"), wx.showToast({
                title: "无法识别"
            });
        });
    },
    onHide: function() {
        console.log("anime.detail.onhide");
    },
    onUnload: function() {
        console.log("anime.detail.onunload");
    },
    tapDownload: function(o) {
        console.log("点击漫画下载"), console.log(o), null != o.currentTarget.dataset.url ? this.downloadFromUrl() : wx.showToast({
            icon: "none",
            title: "图片加载异常"
        });
    },
    showRewardAdConfirm: function() {
        var o = this;
        wx.showModal({
            title: "提示",
            content: "观看完整视频广告，才能下载哦！",
            cancelText: "忍痛放弃",
            confirmText: "立即下载",
            confirmColor: "#576B95",
            success: function(e) {
                e.confirm ? (console.log("用户点击确定"), o.showRewardAd()) : e.cancel && console.log("用户点击取消");
            }
        });
    },
    showRewardAd: function() {
        rewardedVideoAd.show().then(function() {
            console.log("激励广告show");
        }).catch(function() {
            rewardedVideoAd.load().then(function() {
                return rewardedVideoAd.show();
            }).catch(function(o) {
                console.log("激励视频 广告显示失败");
            });
        });
    },
    downloadFromUrl: function() {
        console.log("download from url");
        var o = this.data.resurl;
        console.log(o), wx.showLoading({
            title: "正在保存"
        }), wx.downloadFile({
            url: o,
            success: function(o) {
                wx.saveImageToPhotosAlbum({
                    filePath: o.tempFilePath,
                    success: function(o) {
                        console.log("写入相册成功"), wx.hideLoading(), wx.showToast({
                            title: "保存成功",
                            icon: "success",
                            duration: 1e3
                        }), wx.setStorageSync("clickAnimeAd", 0);
                    }
                });
            },
            fail: function(o) {
                console.log("网络下载失败");
            }
        });
    },
    onShareAppMessage: function(o) {
        return console.log("anime.detail.detail:onshareappmessage"), console.log(o), "button" === o.from ? console.log("按钮内分享") : "menu" === o.from && console.log("右上角菜单分享"), 
        {
            title: "一键生成个性卡通照，快来试试吧！",
            imageUrl: this.data.resurl,
            path: "/pages/anime/detail/detail?resurl=" + this.data.resurl,
            success: function(o) {
                console.log("转发成功");
            },
            fail: function() {
                console.log("转发失败");
            }
        };
    }
});